import baseRequest from "@/utils/request";

/**
 * 重写request
 * @param config
 * @returns {Promise | Promise<unknown>}
 */
const request = function (config) {
  config.baseURL = process.env.VUE_APP_BASE_API + '/transferWork'
  return baseRequest(config)
}

/**
 * 获取列表数据
 * @param params
 * @returns {Promise|Promise<*>}
 */
export function getTransferList(params){
  return request({
    url: '/getTransferList',
    params
  })
}

/**
 * 获取调货工单详情
 * @param id
 * @returns {Promise|Promise<*>}
 */
export function getTransferInfo(id){
  return request({
    url: `/getTransferInfo/${id}`,
  })
}

/**
 * 保存
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function saveTransferGoodsNum(data){
  return request({
    url: `/saveTransferGoodsNum`,
    data,
    method: 'put',
  })
}

/**
 * 完成调货
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function finishTransfer(data){
  return request({
    url: `/finishTransfer`,
    data,
    method: 'put',
    handleError: true
  })
}


/**
 * 导出拣货单
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function exportTransferThermalPdf(data){
  return request({
    url: `/exportTransferThermalPdf`,
    method: 'post',
    data,
    responseType: "arraybuffer",
    isNotJson: true,
    timeout: 60000 * 5, // 1分钟
    handleError: true,
  })
}

/**
 * 保存商品数量
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function saveRlGoodsNum(data){
  return request({
    url: `/saveRlGoodsNum`,
    method: 'put',
    data,
    handleError: true,
  })
}
